/*
 * MediaFormat.h
 *
 *  Created on: 2015年6月27日
 *      Author: chuanjiang.zh@qq.com
 */

#ifndef MEDIAFORMAT_H_
#define MEDIAFORMAT_H_

#include "MediaType.h"
#include <string>


namespace av
{


class MediaFormat
{
public:

	int m_duration;         // millisecond

	int m_codec;
	int m_width;
	int m_height;
	int m_framerate;
	int m_bitrate;
	int m_profile;			/// video codec profile
    int m_clockRate;

	int m_audioCodec;
	int m_audioProfile;		/// audio codec profile
	int m_channels;
	int m_sampleRate;
	int m_sampleBits;
	int m_frameSize;
	int m_audioBitrate;
    int m_audioRate;        ///


    std::string m_videoProp;
	std::string m_audioConfig;

	MediaFormat():
		m_duration(),
		m_codec(MEDIA_CODEC_NONE),
		m_width(),
		m_height(),
		m_framerate(),
		m_bitrate(),
		m_profile(),
        m_clockRate(),
		m_audioCodec(MEDIA_CODEC_NONE),
		m_audioProfile(),
		m_channels(0),
		m_sampleRate(0),
		m_sampleBits(16),
		m_frameSize(1024),
		m_audioBitrate(),
        m_audioRate(),
		m_videoProp(),
		m_audioConfig()
	{
	}

	~MediaFormat()
	{
	}

	bool hasVideo() const
	{
		return (m_codec != 0);
	}

	bool hasAudio() const
	{
		return (m_audioCodec != 0);
	}

	bool isValid() const
	{
		return (m_codec != 0) || (m_audioCodec != 0);
	}

	int getAudioBitrate() const
	{
		return m_sampleRate * m_channels * m_sampleBits;
	}

	size_t getVideoPropSize() const
	{
		return m_videoProp.size();
	}

	const uint8_t* getVideoProp() const
	{
		return (const uint8_t*)m_videoProp.c_str();
	}

	size_t getAudioConfigSize() const
	{
		return m_audioConfig.size();
	}

	const uint8_t* getAudioConfig() const
	{
		return (const uint8_t*)m_audioConfig.c_str();
	}

	void setVideoProp(const uint8_t* data, size_t length)
	{
		m_videoProp.assign((const char*)data, length);
	}

	void setVideoProp(const char* data, size_t length)
	{
		m_videoProp.assign(data, length);
	}

	void setAudioConfig(const uint8_t* data, size_t length)
	{
		m_audioConfig.assign((const char*)data, length);
	}

	void setAudioConfig(const char* data, size_t length)
	{
		m_audioConfig.assign(data, length);
	}

	void clear()
	{
		m_duration = 0;
		m_codec = MEDIA_CODEC_NONE;
		m_width = 0;
		m_height = 0;
		m_framerate = 0;
		m_bitrate = 0;
		m_profile = 0;
        m_clockRate = 0;

		m_audioCodec = MEDIA_CODEC_NONE;
		m_audioProfile = 0;
		m_channels = 0;
		m_sampleRate = 0;
		m_sampleBits = 16;
		m_frameSize = 1024;
		m_audioBitrate = 0;
        m_audioRate = 0;

		m_videoProp.clear();
		m_audioConfig.clear();
	}

	void copyVideo(const MediaFormat& fmt)
	{
		m_duration = fmt.m_duration;

		m_codec = fmt.m_codec;
		m_width = fmt.m_width;
		m_height = fmt.m_height;
		m_profile = fmt.m_profile;
		m_framerate = fmt.m_framerate;
		m_bitrate = fmt.m_bitrate;
		m_clockRate = fmt.m_clockRate;

		m_videoProp = fmt.m_videoProp;
	}

	void copyAudio(const MediaFormat& fmt)
	{
		m_audioCodec = fmt.m_audioCodec;
		m_channels = fmt.m_channels;
		m_sampleRate = fmt.m_sampleRate;
		m_sampleBits = fmt.m_sampleBits;
		m_audioProfile = fmt.m_audioProfile;
		m_audioBitrate = fmt.m_audioBitrate;
		m_audioRate = fmt.m_audioRate;

		m_frameSize = fmt.m_frameSize;

		m_audioConfig = fmt.m_audioConfig;
	}

};




} /* namespace av */

#endif /* MEDIAFORMAT_H_ */
